# Makefile for GamingLibraries

# The C compiler
CC = cc

# Flags passed to the C compiler
CFLAGS = -fpic -Wall -O2 -ggdb3
# Flagsrequired to compile things depending on SDL
SDLFLAGS = -lSDL -lSDL_image

# Object files: one for each C code file, all eventually linked
# together to make the library.
OBJS = LinkedList.o DoublyLinkedList.o TopDownView.o File.o \
	String.o Sort.o Math.o Surface.o Vector.o StringConvert.o \
	DynamicArray.o BigInt.o BigNum.o Container.o

# The library's name
LIB = libGame.so.1.0

# Where to put the library
LIBDIR = /usr/lib

# Where to put the includes
INCLUDEDIR = /usr/include

# Default target: makes everything
all : $(LIB)

# Install the library
install : $(LIB)
	if ! [ -d $(INCLUDEDIR)/GamingLibraries ]; then\
		mkdir $(INCLUDEDIR)/GamingLibraries;\
	fi
	cp *.h $(INCLUDEDIR)/GamingLibraries
	cp $(LIB) $(LIBDIR)
	ln -sf $(LIBDIR)/libGame.so.1.0 $(LIBDIR)/libGame.so
	ln -sf $(LIBDIR)/libGame.so.1.0 $(LIBDIR)/libGame.so.1
	ldconfig $(LIBDIR)

# Uninstall the library
uninstall :
	$(RM) -r $(INCLUDEDIR)/GamingLibraries
	$(RM) $(LIBDIR)/libGame.so*
	ldconfig $(LIBDIR)

# Build the library
$(LIB) : $(OBJS)
	$(CC) -shared -Wl,-soname,$(LIB) -o $(LIB) $(OBJS) $(CFLAGS) $(SDLFLAGS)

# Build the object files (pattern rule)
$(OBJS) : %.o : %.c
	$(CC) -c $(CFLAGS) $< -o $@

# Remove everything generated by the build
clean :
	$(RM) $(OBJS) $(LIB)

# Remove everything generated by the build, and backups of source.
# Should be run before committing changes to source control.
realclean : clean
	$(RM) *~
